<%@ Import Namespace="Common"%>
<%@ Import Namespace="System.Runtime.Remoting"%>
<%@ Import Namespace="SystemFrameworks"%>
<%@ Application Language="C#" %>

<script runat="server">

    private static String appRoot;
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        //OnApplicationStart(Context.Server.MapPath(Context.Request.ApplicationPath));
        //string configPath = System.IO.Path.Combine(Context.Server.MapPath(Context.Request.ApplicationPath), "remotingclient.cfg");
        //if (System.IO.File.Exists(configPath))
        //RemotingConfiguration.Configure(configPath);

        try
        {
            //CrearCachePaises();
            //CrearCacheDepartamentos();
            //CrearCacheMunicipios();

            //Application[Utilidad._APPLICATION_BASE_PATH] = DefaultPath();
            Application[Utilidad._APPLICATION] = Utilidad.SistemaInformacion.SIPA;

        }
        catch (Exception ex)
        {
            throw new ApplicationExceptionManager(ex.Message, ex);
        }

    }
    /// <summary>
    ///     Function to be called by Application_OnStart as described in the
    ///     class description. Initializes the application root.
    ///     <param name="myAppPath">The path of the running application.</param>
    /// </summary>
    public static void OnApplicationStart(String myAppPath)
    {
        appRoot = myAppPath;
        ConfigurationSettings.GetConfig("appSettings");
    }
    //protected string DefaultPath()
    //{
//        string mstrPort = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
        //string mstrProtocol = HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];

        //if (mstrPort == null || mstrPort == "80" || mstrPort == "443")
        //{
        //    mstrPort = String.Empty;
        //}
        //else
        //{
        //    mstrPort = ":" + mstrPort;
        //}

        //if (mstrProtocol == null || mstrProtocol == "0")
        //{
        //    mstrProtocol = "http://";
        //}
        //else
        //{
        //    mstrProtocol = "https://";
        //}

        //string ruta = "";
        ////if (HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString() == "localhost")
        ////    ruta = ConfigurationManager.AppSettings["UrlImages"].ToString() +
        ////           HttpContext.Current.Request.ApplicationPath;
        ////else
        ////    ruta = HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + mstrPort + HttpContext.Current.Request.ApplicationPath;
        
        //// *** Construccion del Url base el cual apunta  a la raiz de la aplicacion

        //return mstrProtocol + ruta;

    //}
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        Session.Add("cambioclave", "n");
        Session.Add("DiasExpiracionClave", 0);
        Session.Add("DiasPreavisoExpiracionClave", 0);
        Session.Add("MaxFilasGrid", 10);
        Session.Add("CuentaAdmin", "admin");
        Session.Add("Usuario", new Common.objUsuario());
        // Variable que almacena el NOMBRE del cache utilizado para almacenar las opciones del menu
        Session.Add(Utilidad._CACHE_OPCIONES_PERFIL, Utilidad._CACHE_OPCIONES_PERFIL + this.Session.SessionID);

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
